package Day2025_01_18;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

public class UDPDictServer extends UDPEchoServer{
    // 定义一个字典Map
    Map<String, String> map;

    public UDPDictServer(int port) throws SocketException {
        super(port);
        map = new HashMap<>();
        map.put("apple", "苹果");
        map.put("banana", "香蕉");
        map.put("orange", "橙子");
    }

    @Override
    protected String process(String key) {
        String response = map.getOrDefault(key, "查无此词");
        return response;
    }

    public static void main(String[] args) throws IOException {
        UDPDictServer server = new UDPDictServer(8888);
        server.start();
    }
}








